//
//  WWTabBar.m
//  Shopping
//
//  Created by 张湾湾 on 16/8/18.
//  Copyright © 2016年 张湾湾. All rights reserved.
//

#import "WWTabBar.h"

@interface WWTabBar ()
@property (nonatomic,strong)UIButton *shopCartButton;

@end

@implementation WWTabBar

- (instancetype)initWithFrame:(CGRect)frame{
    if (self = [super initWithFrame:frame]) {
                    
    }
    
    return self;
}

//遍历子控制器
- (void)layoutSubviews{
    [super layoutSubviews];
 
    for (UIControl *tabBarButton in self.subviews) {
        if ([tabBarButton isKindOfClass:NSClassFromString(@"UITabBarButton")]) {
            [tabBarButton addTarget:self action:@selector(tabBarButtonClick:) forControlEvents:UIControlEventTouchUpInside];
        }
    }
}
//动画效果
- (void)tabBarButtonClick:(UIControl *)tabBarButton
{
    for (UIView *imageView in tabBarButton.subviews) {
        if ([imageView isKindOfClass:NSClassFromString(@"UITabBarSwappableImageView")]) {
            //需要实现的帧动画,这里根据需求自定义
            CAKeyframeAnimation *animation = [CAKeyframeAnimation animationWithKeyPath:@"transform.scale"];
            animation.values = @[@1.0,@1.3,@0.9,@1.15,@0.95,@1.02,@1.0];
            animation.duration = 1;
            animation.calculationMode = kCAAnimationCubic;
            //把动画添加上去就OK了
            [imageView.layer addAnimation:animation forKey:nil];
        }
    }
}

#pragma mark - 懒加载 -
- (UIButton *)shopCartButton{
    if (!_shopCartButton) {
        UIButton * shopCarButton = [[UIButton alloc]init];
        [shopCarButton setImage:[UIImage imageNamed:@"shopCart"] forState:UIControlStateNormal];
        _shopCartButton = shopCarButton;
        //添加点击事件
        [shopCarButton addTarget:self action:@selector(didClickShopCartButton) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:shopCarButton];
        
    }
    return _shopCartButton;
}
@end
